"use strict";
cc._RF.push(module, '2a7a7CMoCBF6ZdR9BcMvwiV', 'audioManger');
// script/audioManger.js

'use strict';

var audioManger = new Object();
var com = require('Common');

//初始化audioManger
audioManger.init = function () {
    if (this.yinLiang != null && this.yinXiao != null) {
        return;
    }
    var yinLiangS = com.soundYinliang;
    //cc.log('audioManger10:yinLiangS=====' + yinLiangS)
    var yinLiang = 0.5;
    if (yinLiangS != null) {
        yinLiang = parseFloat(yinLiangS);
    } else {
        this.setYinLiang(0.5);
    }

    var yinXiaoS = com.effectYinliang;
    var yinXiao = 0.5;
    if (yinXiaoS != null) {
        yinXiao = parseFloat(yinXiaoS);
    } else {
        this.setYinXiao(yinXiao);
    }

    this.yinLiang = yinLiang;
    this.yinXiao = yinXiao;
};

//设置音乐音量和音效音量
audioManger.setYinLiang = function (yinliang) {
    //cc.log('audioManger:set yinliang : ' + yinliang);
    com.soundYinliang = yinliang;
    this.soundYL = yinliang;
    //cc.log('--------audioManger: this.bgId : ' + this.bgId + ' yl=' +this.soundYL);
    if (this.bgId != null) {
        cc.audioEngine.setVolume(this.bgId, this.soundYL);
    }
};
audioManger.setYinXiao = function (yinXiao) {
    //cc.log('audioManger:set YinXiao : ' + yinXiao);//haoyu以后做好音效的调试后也注释掉这个log
    //cc.sys.localStorage.setItem('yinXiao', yinXiao);
    com.effectYinliang = yinXiao;
    this.yinXiao = yinXiao;
};

//获取音乐音量和音效音量
audioManger.getYinLiang = function () {
    this.init();
    return this.yinLiang;
};
audioManger.getYinXiao = function () {
    this.init();
    return this.yinXiao;
};

//播放音乐音量和音效音量的大小设置
audioManger.playYinLiang = function (audio, loop) {
    this.init();
    if (this.yinLiang <= 0) {
        return -1;
    }
    var audioID = cc.audioEngine.play(audio, loop, this.yinLiang);
    return audioID;
};
audioManger.playYinXiao = function (audio) {
    this.init();
    if (this.yinXiao <= 0) {
        return -1;
    }
    var audioID = cc.audioEngine.play(audio, false, this.yinXiao);
    return audioID;
};

//播放或停止背景音乐
audioManger.playerBgMusic = function (audio) {
    if (this.bgId != null) {
        cc.audioEngine.stop(this.bgId);
        this.bgId = null;
    }
    this.bgId = this.playYinLiang(audio, true);
};
audioManger.stopBgMusic = function () {
    if (this.bgId != null) {
        cc.audioEngine.stop(this.bgId);
    }
};

module.exports = audioManger;

cc._RF.pop();